﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<fmt:setBundle basename="ApplicationMessage" />
<fmt:setLocale value="zh_CN" />

<sec:authentication property="principal" var="currentPrincipal" scope="page" />

<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <%@ include file="/WEB-INF/include/meta.jsp"%>
  <%@ include file="/WEB-INF/include/css.jsp"%>
</head>

<body>
  <%@ include file="/WEB-INF/include/header.jsp"%>
  <%@ include file="/WEB-INF/include/menu.jsp"%>

  <div class="container main-content">
    <div class="panel panel-default x-panel x-panel-layout">
      <div class="panel-heading">
        <ol class="breadcrumb">
          <li><a href="${ctx.host}/ecommerce">电商管理</a></li>
          <li class="active">订单管理</li>
        </ol>
      </div>

      <div class="panel-body">
        <div class="col-xs-2 x-panel-layout-left no-horizontal-padding">
          <%@ include file="/WEB-INF/include/submenu.jsp"%>
        </div>

        <div class="col-xs-10 x-panel-layout-right">
          <form id="orders-search-form" class="form-horizontal" method="GET" action="${ctx.host}/orders-search">
            <div class="x-breadcrumb-wrapper">
              <div class="x-breadcrumb clearfix">
                <h2><i class="glyphicon glyphicon-fire"></i>&nbsp;&nbsp;<span>订单管理&nbsp;-&nbsp;订单查询</span></h2>
                <c:if test="${not currentPrincipal.customerServer and not currentPrincipal.onlineCoach and not currentPrincipal.creditProductManager}">
                  <div class="pull-right">
                    <c:choose>
                      <c:when test="${not empty currentPrincipal.site}">
                        <span class="current-branchCode">${currentPrincipal.site.name}</span>
                      </c:when>
                      <c:otherwise>
                        <select name="siteId"<c:if test="${param.orderType == 'online' or param.orderType == 'others'}"> class="hide"</c:if>>
                          <option value="">所有门店</option>
                          <c:forEach var="site" items="${persist.getSites(currentPrincipal.id)}">
                            <option value="${site.id}" ${site.id == param.siteId ? 'selected' : ''}>${site.name}</option>
                          </c:forEach>
                        </select>
                      </c:otherwise>
                    </c:choose>
                  </div>
                </c:if>
              </div>
            </div>

            <div class="x-breadcrumb-wrapper top-margin-20" style="position: relative;">
              <input type="hidden" name="filter" value="true" >
              <div class="form-group x-form-group">
                <label class="col-xs-2 control-label">订单号</label>
                <div class="col-xs-3" style="width: 30%;">
                  <input type="text" class="form-control" name="orderCode" value="${param.orderCode}" placeholder="支持模糊查询"/>
                </div>
                <label class="col-xs-2 control-label">姓名</label>
                <div class="col-xs-3" style="width: 30%;">
                  <input type="text" class="form-control" name="name" value="${param.name}" placeholder="支持模糊查询"/>
                </div>
              </div>
              <div class="form-group x-form-group">
                <label class="col-xs-2 control-label">手机号</label>
                <div class="col-xs-3" style="width: 30%;">
                  <input type="text" class="form-control" name="mobile" value="${param.mobile}" placeholder="支持模糊查询"/>
                </div>
                <label class="col-xs-2 control-label">支付状态</label>
                <div class="col-xs-3" style="width: 30%;">
                  <select name="paymentStatus" class="form-control" data-validate="required">
                    <option value=""></option>
                    <option value="unpaid" ${param.paymentStatus == 'unpaid' ? 'selected' : ''}>待支付</option>
                    <option value="paid" ${param.paymentStatus == 'paid' ? 'selected' : ''}>已支付</option>
                    <option value="refunding" ${param.paymentStatus == 'refunding' ? 'selected' : ''}>待退款</option>
                    <option value="refunded" ${param.paymentStatus == 'refunded' ? 'selected' : ''}>已退款</option>
                    <option value="systemRefunded" ${param.paymentStatus == 'systemRefunded' ? 'selected' : ''}>系统已退款</option>
                    <option value="canceled" ${param.paymentStatus == 'canceled' ? 'selected' : ''}>系统取消</option>
                  </select>
                </div>
              </div>
              <div class="form-group x-form-group">
                <label class="col-xs-2 control-label">下单时间</label>
                <div class="col-xs-3" style="width: 60%;">
                  <div class="input-group">
                    <input type="text" class="form-control date" name="createTimeStart" value="${param.createTimeStart}" placeholder="开始时间"/>
                    <span class="input-group-addon"></span>
                    <input type="text" class="form-control date" name="createTimeEnd" value="${param.createTimeEnd}" placeholder="结束时间"/>
                  </div>
                </div>
              </div>
              
              <div class="x-breadcrumb-wrapper clearfix" style="position: relative; margin-top: 15px;">
                <c:if test="${(not empty param.orderType or not empty orders) and not currentPrincipal.onlineCoach and not currentPrincipal.creditProductManager}">
                  <c:if test="${empty param.siteId and not currentPrincipal.siteManager and not currentPrincipal.siteServer and not currentPrincipal.areaManager and not currentPrincipal.areaServer}">
                    <div class="btn-group pull-left">
                      <a id="online" href="javascript:void(0);" class="btn btn-${param.orderType == 'online' ? 'success' : 'default'} x-btn btn-shadow btn-shadow-${param.orderType == 'online' ? 'success' : 'default'}">
                        &nbsp;&nbsp;线上订单
                      </a>
                    </div>
                  </c:if>
                  <div class="btn-group pull-left">
                    <a id="individual" href="javascript:void(0);" class="btn btn-${param.orderType == 'individual' ? 'success' : 'default'} x-btn btn-shadow btn-shadow-${param.orderType == 'individual' ? 'success' : 'default'}">
                      &nbsp;&nbsp;1V1线下减脂营
                    </a>
                  </div>
                  <div class="btn-group pull-left">
                    <a id="group" href="javascript:void(0);" class="btn btn-${param.orderType == 'group' ? 'success' : 'default'} x-btn btn-shadow btn-shadow-${param.orderType == 'group' ? 'success' : 'default'}">
                      &nbsp;&nbsp;线下团课
                    </a>
                  </div>
                  <div class="btn-group pull-left">
                    <a id="year" href="javascript:void(0);" class="btn btn-${param.orderType == 'year' ? 'success' : 'default'} x-btn btn-shadow btn-shadow-${param.orderType == 'year' ? 'success' : 'default'}">
                      &nbsp;&nbsp;月卡/季卡订单
                    </a>
                  </div>
                  <c:if test="${empty param.siteId and not currentPrincipal.siteManager and not currentPrincipal.siteServer and not currentPrincipal.areaManager and not currentPrincipal.areaServer}">
                    <div class="btn-group pull-left">
                      <a id="others" href="javascript:void(0);" class="btn btn-${param.orderType == 'others' ? 'success' : 'default'} x-btn btn-shadow btn-shadow-${param.orderType == 'others' ? 'success' : 'default'}">
                        &nbsp;&nbsp;周边订单
                      </a>
                    </div>
                  </c:if>
                  <input type="hidden" id="orderType" name="orderType">
                </c:if>
                
                <div class="btn-group pull-right">
                  <button id="sub_btn" type="button" class="btn btn-success btn-shadow btn-shadow-success x-btn">查询</button>&nbsp;&nbsp;&nbsp;&nbsp;
                </div>
              </div>
            </div>
          </form>

          <c:if test="${not empty orders}">
            <table class="table table-striped table-hover x-table" style="margin-bottom:20px;">
              <thead>
                <tr>
                  <th>订单类型</th>
                  <th>订单号</th>
                  <th>下单用户</th>
                  <th>产品</th>
                  <th>门店</th>
                  <th>订单金额</th>
                  <th>创建时间</th>
                  <th>订单状态</th>
                  <th>销售人员</th>
                  <th class="text-center">操作</th>
                </tr>
              </thead>
              <tbody>
                <c:forEach var="order" items="${orders}">
                  <tr>
                    <td>${order.orderType.description}</td>
                    <td>
                      <a href="${ctx.host}/-orders/${order.id}">${order.code}</a><br>
                      <fmt:formatDate value="${order.payTime}" pattern="yyyy-MM-dd HH:mm:ss"/>
                    </td>
                    <td style="max-width: 150px;" class="ellipsis">
                      ${order.user.name}（${order.user.wechat.code}）<br>
                      ${order.user.mobile}
                    </td>
                    <td style="max-width: 240px;" class="ellipsis">${order.product.name}</td>
                    <td style="max-width: 150px;" class="ellipsis">${order.site.name}</td>
                    <td style="max-width: 150px;" class="ellipsis">
                      <fmt:formatNumber value="${order.price / 100}" pattern="0.00" maxFractionDigits="2" />
                    </td>
                    <td style="max-width: 150px;" class="ellipsis">
                      <fmt:formatDate value="${order.createTime}" pattern="yyyy-MM-dd HH:mm"/>
                    </td>
                    <td style="max-width: 150px;" class="ellipsis">
                      ${order.orderStatus.description} <br />
                      ${order.paymentStatus.description}
                    </td>
                    <td>${empty order.salesman ? '-' : order.salesman.name}</td>
                    <td class="text-center">
                      <a href="${ctx.host}/-orders/${order.id}">详情</a>&nbsp;&nbsp;
                      <c:if test="${order.orderType.isOnline() and order.orderStatus == 'CREATED'}">
                        <a href="${ctx.host}/online-orders/${order.id}/pay" data-target="#pay" data-toggle="modal">已收款</a>&nbsp;&nbsp;
                      </c:if>
                      <c:if test="${order.orderType.isIndividual() || order.orderType.isYear()}">
                        <c:if test="${order.unpaid}">
                          <c:if test="${order.deposit == 0}">
                            <a href="${ctx.host}/-orders/${order.id}/deposit" data-target="#deposit" data-toggle="modal">定金</a>&nbsp;&nbsp;
                          </c:if>
                          <a href="${ctx.host}/-orders/${order.id}/offer" data-target="#offer" data-toggle="modal">部分金额</a>&nbsp;&nbsp;
                        </c:if>
                      </c:if>
                      <c:if test="${order.orderType.isOffline() and order.unpaid}">
                        <a href="${ctx.host}/-orders/${order.id}/pay" data-target="#pay" data-toggle="modal">手动支付</a>&nbsp;&nbsp;
                      </c:if>
                      <c:if test="${order.availableCancel()}">
                        <a href="${ctx.host}/-orders/${order.id}/close" data-target="#close" data-toggle="modal">关闭</a>&nbsp;&nbsp;
                      </c:if>
                      <c:if test="${order.availableRefund() and !currentPrincipal.siteServer and !currentPrincipal.areaServer}">
                        <a href="${ctx.host}/-orders/${order.id}/refund" data-target="#refund" data-toggle="modal">退款</a>&nbsp;&nbsp;
                      </c:if>
                      <c:if test="${order.orderType.isOthers() and order.orderStatus == 'SHIPPING'}">
                        <a href="${ctx.host}/others-orders/${order.id}/ship" data-target="#ship" data-toggle="modal">发货</a>&nbsp;&nbsp;
                      </c:if>
                      <c:choose>
                        <c:when test="${order.orderType.isOffline()}">
                          <c:if test="${order.availableChangeSalesman()}">
                            <a href="${ctx.host}/-orders/${order.id}/change-salesman" data-target="#change-salesman" data-toggle="modal">销售人员</a>
                          </c:if>
                        </c:when>
                        <c:otherwise>
                          <a href="${ctx.host}/-orders/${order.id}/remarks" data-target="#remark" data-toggle="modal">备注</a>&nbsp;&nbsp;
                        </c:otherwise>
                      </c:choose>
                      <c:if test="${!order.orderType.isGroup()}">
                        <c:if test="${order.paymentStatus.paid and empty persist.orderInvoiceRecord(order.id)}">
                          <a href="${ctx.host}/-orders/${order.id}/invoice" data-target="#invoice" data-toggle="modal">开具发票</a>&nbsp;&nbsp;
                        </c:if>
                        <c:if test="${order.paymentStatus.paid}">
                          <a href="${ctx.host}/-orders/${order.id}/distribution-channel" data-target="#distribution-channel" data-toggle="modal">销售渠道</a>&nbsp;&nbsp;
                        </c:if>
                      </c:if>
                    </td>
                  </tr>
                </c:forEach>
              </tbody>
            </table>
          </c:if>

          <div class="form-horizontal clearfix">
            <c:if test="${refer == 'search'}">
              <div class="form-group pull-left" style="width: 60%">
                <label class="control-label col-xs-3">查询总计：</label>
                <div class="col-xs-4" style="padding-left: 0px;">
                  <p class="form-control-static">${total}条记录</p>
                </div>
              </div>
            </c:if>

            <jsp:include page="/WEB-INF/include/page.jsp">
              <jsp:param name="url" value="orders-search" />
              <jsp:param name="queryString" value="${queryString}" />
            </jsp:include>
          </div>
        </div>
      </div>
    </div>
  </div>

  <%@ include file="/WEB-INF/include/script.jsp"%>

  <d:resource root="${ctx.resource}/build" type="script" src="js/page/ecommerce/order/order-search-list.js">
    <script type="text/javascript">
      require(['page/ecommerce/order/order-search-list'],function(page){
        page.init();
      })
    </script>
  </d:resource>
</body>
</html>